/*
 * Copyright 2011 David Scherzinger, Joe Quinn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pisa;

import java.awt.*;
import javax.swing.*;

public class PuzzFrame extends JFrame {
	private final int editMode = 0, solveMode = 1;
	private static JTabbedPane puzzlePane = new JTabbedPane();
	
	public static void main(String[] args) {
		new PuzzFrame();
	}
	
	public PuzzFrame() {
		super("PISA");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(new Dimension(600,500));
		setLocation(200, 150);
        initMenu();
        add(puzzlePane);
        setVisible(true);
	}
	
	/**
	 * @author David Scherzinger
	 * Sets up the menu bar
	 */
	private void initMenu() {
		//TODO Insert listeners on menu items
		
		JMenuBar menu = new JMenuBar();
		
		// create File menu
		JMenuItem newItem = new JMenuItem("Create New Puzzle");
		JMenuItem editItem = new JMenuItem("Edit Puzzle");
		JMenuItem solveItem = new JMenuItem("Solve Puzzle");
		JMenuItem saveItem = new JMenuItem("Save");
		JMenuItem saveAsItem = new JMenuItem("Save As");
		JMenuItem exitItem = new JMenuItem("Exit");

		JMenu fileMenu = new JMenu("File");
		fileMenu.add(newItem);
		fileMenu.add(editItem);
		fileMenu.add(solveItem);
		fileMenu.add(new JSeparator());
		fileMenu.add(saveItem);
		fileMenu.add(saveAsItem);
		fileMenu.add(new JSeparator());
		fileMenu.add(exitItem);
		
		// create Options menu
		JMenuItem toggleRulesItem = new JCheckBoxMenuItem("Show Rules", true);
		JMenuItem prefsItem = new JMenuItem("Preferences");
		
		JMenu optionsMenu = new JMenu("Options");
		optionsMenu.add(toggleRulesItem);
		optionsMenu.add(prefsItem);
		
		// assemble the menu
		menu.add(fileMenu);
		menu.add(optionsMenu);
		
		setJMenuBar(menu);
	}

	/**
	 * @author
	 * Brings up another window where the user specifies the main type of the
	 * puzzle, puzzle size, extra rules, and other options.
	 * Upon closing the window, opens a new tab with a "blank" grid designed
	 * for creating the desired puzzle type. 
	 */
	private void newPuzzle() {
		//TODO Clicking "Create New Puzzle" calls this
	}

	/**
	 * @author
	 * Opens an open file dialog, where the user specifies which puzzle to
	 * load for editing.
	 * Opens a new tab with current state of the puzzle.
	 * 
	 * File format details dependent on puzzle, so this should create a new
	 * puzzle instance, then tell that read the file.
	 */
	private void editPuzzle() {
		//TODO Clicking "Edit Puzzle" calls this
	}
	
	/**
	 * @author
	 * Opens a file dialog, where the user specifies which puzzle to load
	 * for solving.
	 * Opens a new tab with current state of the puzzle.
	 * 
	 * File format details dependent on puzzle, so this should create a new
	 * puzzle instance, then tell that read the file.
	 */
	private void solvePuzzle() {
		//TODO Clicking "Solve Puzzle" calls this
	}

	/**
	 * @author
	 * If the puzzle in the tab currently being viewed has an associated file
	 * path, saves puzzle to a file at that location.
	 * Otherwise, calls saveAs(). 
	 * 
	 * File format details dependent on puzzle, so this should give the puzzle
	 * instance a write location.
	 */
	private void save() {
		//TODO Clicking "Save" calls this
	}

	/**
	 * @author
	 * Opens a file dialog, where the user specifies a path to save the
	 * current puzzle to.
	 * 
	 * File format details dependent on puzzle, so this should create a new
	 * puzzle instance, then tell that read the file.
	 */
	private void saveAs() {
		//TODO Clicking "Save As" calls this
	}
}